//
//  LGMineHomeItemCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/10/10.
//

#import "LGMineHomeItemCell.h"

@interface LGMineHomeItemCell()
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UIImageView *iconView;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UIImageView *tipView;
/**   */
@property (nonatomic , strong)UILabel *numberLabel;
/**   */
@property (nonatomic , strong)UILabel *unitLabel;
/**   */
@property (nonatomic , strong)UILabel *monthLabel;
/**   */
@property (nonatomic , strong)UILabel *addNumLabel;

@end

@implementation LGMineHomeItemCell

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    [self.iconView sd_setImageWithURL:[NSURL URLWithString:LGNSString(dataDic[@"icon"])]];
    self.titleLabel.text = LGNSString(dataDic[@"title"]);
    self.numberLabel.text = LGNSString(dataDic[@"number"]);
    self.unitLabel.text = LGNSString(dataDic[@"unit"]);
    self.addNumLabel.text = [NSString stringWithFormat:@"+%@",dataDic[@"add_num"]];
}

-(void)setShowTip:(BOOL)showTip{
    _showTip = showTip;
    self.tipView.hidden = !showTip;
}


#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.clipsToBounds = YES;
    self.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.baseView];
    [self.baseView addSubview:self.iconView];
    [self.baseView addSubview:self.titleLabel];
    [self.baseView addSubview:self.tipView];
    [self.baseView addSubview:self.numberLabel];
    [self.baseView addSubview:self.unitLabel];
    [self.baseView addSubview:self.monthLabel];
    [self.baseView addSubview:self.addNumLabel];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.bottom.right.equalTo(self.contentView);
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconView.mas_right).offset(viewPix(4));
        make.right.equalTo(self.baseView).offset(-viewPix(5));
        make.centerY.equalTo(self.iconView);
    }];
    [self.tipView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.centerY.equalTo(self.iconView);
        make.width.height.equalTo(@(viewPix(12)));
    }];
    [self.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.iconView.mas_bottom).offset(viewPix(8));
        make.left.equalTo(self.iconView);
    }];
    [self.unitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.numberLabel.mas_right).offset(viewPix(2));
        make.centerY.equalTo(self.numberLabel);
    }];
    [self.monthLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.numberLabel.mas_bottom).offset(viewPix(12));
        make.left.equalTo(self.numberLabel);
    }];
    [self.addNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.monthLabel.mas_right).offset(viewPix(4));
        make.centerY.equalTo(self.monthLabel);
    }];
}
-(UIView *)baseView{
    if(!_baseView){
        _baseView = [[UIView alloc] init];
        _baseView.backgroundColor = [UIColor colorWithString:@"#FBFCFF"];
        _baseView.layer.borderColor = [UIColor colorWithString:@"#FFFFFF"].CGColor;
        _baseView.layer.borderWidth = 1.5;
        _baseView.cornerRidus = 15;
    }
    return _baseView;
}

-(UIImageView *)iconView{
    if(!_iconView){
        _iconView = [[UIImageView alloc]initWithFrame:CGRectMake(viewPix(16), viewPix(16), viewPix(20), viewPix(20))];
    }
    return _iconView;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _titleLabel;
}

-(UIImageView *)tipView{
    if(!_tipView){
        _tipView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"grayTip12"]];
    }
    return _tipView;
}

-(UILabel *)numberLabel{
    if(!_numberLabel){
        _numberLabel = [UILabel lableWithText:@"" colorString:@"#4C87FD" textFont:LGFontWeight(20, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _numberLabel;
}

-(UILabel *)unitLabel{
    if(!_unitLabel){
        _unitLabel = [UILabel lableWithText:@"" colorString:@"#999999" textFont:LGFont(12) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _unitLabel;
}

-(UILabel *)monthLabel{
    if(!_monthLabel){
        _monthLabel = [UILabel lableWithText:@"本月" colorString:@"#666666" textFont:LGFont(13) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _monthLabel;
}

-(UILabel *)addNumLabel{
    if(!_addNumLabel){
        _addNumLabel = [UILabel lableWithText:@"" colorString:@"#4C87FD" textFont:LGFontWeight(13, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _addNumLabel;
}

@end
